//
//  DetailVC.m
//  AnimationRecommend
//
//  Created by ljm on 2017/2/20.
//  Copyright © 2017年 ljm. All rights reserved.
//

#import "DetailVC.h"
#import <WebKit/WebKit.h>

@interface DetailVC ()<UITextViewDelegate>

@property(nonatomic,strong) NSMutableArray *BVArray;

@end

@implementation DetailVC

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    [self hideTabBar];
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self showTabBar];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSLog( @" ====== ======\n\n%@",self.url);
    WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
    [self.view addSubview:webView];
    
//    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:webView animated:YES];
//    hud.mode = MBProgressHUDModeIndeterminate;
//    hud.label.text = @"加载中...";

    
    
}

- (void)setupUI {

    self.view.backgroundColor = iCodeTableviewBgColor;
    
//    // 读取文本
//    NSError *error;
//    NSString *text = [NSString stringWithContentsOfFile:[NSBundle.mainBundle URLForResource:@"火影" withExtension:@"txt"].path
//                                               encoding:NSUTF8StringEncoding
//                                                  error:&error];
//    NSLog(@"%@\n%@",text,error);
//    
//    NSString *path = [[NSBundle mainBundle] pathForResource:@"火影" ofType:@"txt"];;
//    NSString *text = [NSString stringWithContentsOfFile:path encoding:NSUTF16StringEncoding error:nil];
    
    
    // 初始化bookView
//    self.bookView                     = [[BookTextView alloc] initWithFrame:AAdaptionRect(0, 64/AAdaptionWidth(), kwidth/AAdaptionWidth() , (kheight - 64)/AAdaptionWidth())];
//    self.bookView.textString          = text;// @"jfijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文fijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文fijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文fijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文fijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文fijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文fijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文fijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文fijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文fijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文fijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文fijeifjeifie中文jijfiejifjiefjeifjeif\ndfejife中文";
    
    
//    // 设置段落样式
//    self.bookView.paragraphAttributes = [ParagraphAttributes qingKeBengYue];
//    
//    // 设置富文本
//    self.bookView.attributes          = @[[ConfigAttributedString foregroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.75f]
//                                                                            range:NSMakeRange(0, 9)],
//                                          [ConfigAttributedString font:[UIFont fontWithName:ManYu_FontStr size:22.f/AAdaptionWidth()]
//                                                                 range:NSMakeRange(0, 9)],
//                                          [ConfigAttributedString backgroundColor:iCodeTableviewBgColor
//                                                                            range:NSMakeRange(0, text.length)]
//                                          
//                                          ];
//    
//    
//    _BVArray = [NSMutableArray array];
//    for (NSInteger index = 1 ; index <= 10; index ++) {
//        //保存图文混编模板
//        ExclusionView * exViews = [[ExclusionView alloc]initWithFrame:CGRectMake(0, 0, kwidth/3*2, kheight/3)];
//        exViews.center = CGPointMake(kwidth/2, kheight/2    + kheight*(index - 1));
//        
//        //加载图片
//        UIImageView *imageView = [[UIImageView alloc] initWithFrame:exViews.bounds];
//        NSString *imageName = [NSString stringWithFormat:@"img%ld.jpeg",index ];
//        imageView.image              = [UIImage imageNamed:imageName];
//        [exViews addSubview:imageView];
//        
//        [_BVArray addObject:exViews];
//    }
//    self.bookView.exclusionViews = _BVArray;
//    
//    
//    
//    // 构建view
//    [self.bookView buildWidgetView];
//    [self.view addSubview:self.bookView];
//    
//    
//    // 延时0.01s执行
//    [self performSelector:@selector(event)
//               withObject:nil
//               afterDelay:0.01];

}

//- (void)event {
//    [self.bookView moveToTextPercent:0.00];
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)hideTabBar {
    if (self.tabBarController.tabBar.hidden == YES) {
        return;
    }
    UIView *contentView;
    if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
        contentView = [self.tabBarController.view.subviews objectAtIndex:1];
    else
        contentView = [self.tabBarController.view.subviews objectAtIndex:0];
    contentView.frame = CGRectMake(contentView.bounds.origin.x,  contentView.bounds.origin.y,  contentView.bounds.size.width, contentView.bounds.size.height + self.tabBarController.tabBar.frame.size.height);
    self.tabBarController.tabBar.hidden = YES;
    
}

- (void)showTabBar
{
    if (self.tabBarController.tabBar.hidden == NO)
    {
        return;
    }
    UIView *contentView;
    if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
        
        contentView = [self.tabBarController.view.subviews objectAtIndex:1];
    else
        
        contentView = [self.tabBarController.view.subviews objectAtIndex:0];
    contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y,  contentView.bounds.size.width, contentView.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
    self.tabBarController.tabBar.hidden = NO;
}


@end
